package com.boot.beans;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.IdentityDialect;
import tk.mybatis.mapper.code.Style;
import util.FD;
import util.MathExtend;

@Entity
@Table(name = "t_question")
@NameStyle(Style.normal)
public class Question {
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", unique = true, nullable = false, insertable = false)
	@KeySql(dialect = IdentityDialect.SQLSERVER, useGeneratedKeys = true)
	private Integer				id;
	@FD("科目")
	private String				coursesel;

	@FD("车型")
	private String				cxsel;
	//所有, 小车、货车、客车

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "questionItemId")
	@FD("分类专项")
	private QuestionItem	questionItem;
	private Integer				questionItemId;
	@FD("题型")
	private String				quesType;				//单选题,多选题,判断题
	@FD("分值")
	private Integer				score;					//分数
	@FD("图片")
	private String				imgFile;
	@FD("题目")
	@Column(length = 5000)
	private String				title;
	@FD("答案")
	private String				answer;
	@FD("选项A")
	private String				option1;
	@FD("选项B")
	private String				option2;
	@FD("选项C")
	private String				option3;
	@FD("选项D")
	private String				option4;

	@Column(updatable = false)
	private Integer				zheng;
	@Column(updatable = false)
	private Integer				cuo;

	@FD("解析")
	@Column(length = 5000)
	private String				jiexi;

	@Transient
	private String				answerStu;
	@Transient
	private String				result;

	@Transient
	public Double getPercent() {
		int total = zheng + cuo;
		if (total == 0)
			return 100d;
		return MathExtend.round(zheng * 1.0 / total * 100, 1);
	}

	public String getCxsel() {
		return cxsel;
	}

	public void setCxsel(String cxsel) {
		this.cxsel = cxsel;
	}

	public QuestionItem getQuestionItem() {
		return questionItem;
	}

	public void setQuestionItem(QuestionItem questionItem) {
		this.questionItem = questionItem;
	}

	public Integer getQuestionItemId() {
		return questionItemId;
	}

	public void setQuestionItemId(Integer questionItemId) {
		this.questionItemId = questionItemId;
	}

	public Integer getZheng() {
		return zheng;
	}

	public Integer getCuo() {
		return cuo;
	}

	public void setZheng(Integer zheng) {
		this.zheng = zheng;
	}

	public void setCuo(Integer cuo) {
		this.cuo = cuo;
	}

	@Transient
	public String getImgType() {
		if (imgFile == null || "".equals(imgFile.trim())) {
			return null;
		}
		if (imgFile.endsWith(".mp4")) {
			return "mp4";
		}
		return "img";
	}

	public Integer getId() {
		return id;
	}

	public String getCoursesel() {
		return coursesel;
	}

	public String getQuesType() {
		return quesType;
	}

	public Integer getScore() {
		return score;
	}

	public String getImgFile() {
		return imgFile;
	}

	public String getTitle() {
		return title;
	}

	public String getAnswer() {
		return answer;
	}

	public String getOption1() {
		return option1;
	}

	public String getOption2() {
		return option2;
	}

	public String getOption3() {
		return option3;
	}

	public String getOption4() {
		return option4;
	}

	public String getJiexi() {
		return jiexi;
	}

	public String getAnswerStu() {
		return answerStu;
	}

	public String getResult() {
		return result;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setCoursesel(String coursesel) {
		this.coursesel = coursesel;
	}

	public void setQuesType(String quesType) {
		this.quesType = quesType;
	}

	public void setScore(Integer score) {
		this.score = score;
	}

	public void setImgFile(String imgFile) {
		this.imgFile = imgFile;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setAnswer(String answer) {
		this.answer = answer;
	}

	public void setOption1(String option1) {
		this.option1 = option1;
	}

	public void setOption2(String option2) {
		this.option2 = option2;
	}

	public void setOption3(String option3) {
		this.option3 = option3;
	}

	public void setOption4(String option4) {
		this.option4 = option4;
	}

	public void setJiexi(String jiexi) {
		this.jiexi = jiexi;
	}

	public void setAnswerStu(String answerStu) {
		this.answerStu = answerStu;
	}

	public void setResult(String result) {
		this.result = result;
	}

}
